package com.yxp.webtest;

import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.core.config.Configurator;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/helloAn")
@Slf4j
public class HelloAnnotation extends HttpServlet {

    @Override
    public void init() throws ServletException {
        Configurator.initialize("Log4j2", "log4j2.properties");
    }

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        resp.getOutputStream().write("<h1>hello helloAn </h1>".getBytes());
        // 设置响应内容类型
        resp.setContentType("text/html;charset=UTF-8");

        // 要重定向的新位置
        String site = new String("http://www.runoob.com");

        resp.setStatus(resp.SC_MOVED_TEMPORARILY);
        resp.setHeader("Location", site);
    }

}
